package com.lib724.web;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.inject.Singleton;
import com.javaeedev.lightweight.mvc.Action;
import com.javaeedev.lightweight.mvc.ExceptionResolver;
import com.javaeedev.lightweight.mvc.ModelAndView;

/**
 * Handle exceptions. Just log and re-throw it.
 * 
 * @author Xuefeng
 */
@Singleton
public class ExceptionHandler implements ExceptionResolver {

    private final Log log = LogFactory.getLog(getClass());

    public void init(ServletContext context) throws ServletException {
    }

    public ModelAndView handleException(Action action, Exception e) throws Exception {
        log.warn("Error in action: " + action.getClass().getName(), e);
        return new ModelAndView("errors/404");
    }

}
